package com.example.mac.yuejian14.fragment;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import java.util.List;

import com.example.mac.yuejian14.R;
import com.example.mac.yuejian14.adapter.TeacherListAdapter;
import com.example.mac.yuejian14.bean.TeacherBean;
import com.example.mac.yuejian14.model.TeacherModel;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * A simple {@link Fragment} subclass.
 */
public class TeacherFragment extends Fragment {


    private RecyclerView recyclerView;
    private List mDataList;
    private View view = null;


    public TeacherFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        view =  inflater.inflate(R.layout.fragment_teacher, container, false);
        initViews();
        getData();
        return view;
    }
    private void initViews(){
        recyclerView = (RecyclerView) view.findViewById(R.id.rV_teacher);
        recyclerView.setLayoutManager(new LinearLayoutManager(this.getActivity()));
        recyclerView.setItemAnimator(new DefaultItemAnimator());
    }
    private void getData(){
//
        TeacherModel teacherModel = new TeacherModel();
        Call<List<TeacherBean>> call = teacherModel.getTeacherList();
        call.enqueue(new Callback<List<TeacherBean>>() {
            @Override
            public void onResponse(Call<List<TeacherBean>> call, Response<List<TeacherBean>> response) {
                List<TeacherBean> data = response.body();
                System.out.print("data");
                recyclerView.setAdapter(new TeacherListAdapter(getActivity(),data));
            }

            @Override
            public void onFailure(Call<List<TeacherBean>> call, Throwable t) {
                Toast.makeText(getActivity(),"fail",Toast.LENGTH_SHORT).show();

            }
        });
    }


}
